//
//  ZGLPhotoCell.m
//  Faker
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLPhotoCell.h"
#import "ZGLPhotoModel.h"
#import <UIImageView+AFNetworking.h>

@interface ZGLPhotoCell ()

@property (nonatomic, strong) UIImageView *waterImage;
@property (nonatomic, assign) CGFloat imageHeigh;
@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *rightLabel;

@end


@implementation ZGLPhotoCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _rightLabel = [[UILabel alloc] init];
        _leftLabel = [[UILabel alloc] init];
        _waterImage = [[UIImageView alloc] init];
        [self.waterImage addSubview:_rightLabel];
        [self.waterImage addSubview:_leftLabel];
        [self.contentView addSubview:_waterImage];
    }
    return self;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    [_waterImage setFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY * 375 * 1.3)];
    [self.leftLabel setFrame:CGRectMake(ScaleX * 20, ScaleY * 375 * 1.35, ScaleX * 40, ScaleY * 20)];
    self.leftLabel.textColor = artiColor;
    self.leftLabel.font = [UIFont systemFontOfSize:20];
    [self.rightLabel setFrame:CGRectMake(ScaleX * 50, ScaleY * 375 * 1.35 - ScaleY * 20, ScaleX * 90, ScaleY * 90)];
    self.rightLabel.textColor = artiColor;
    _rightLabel.font = [UIFont systemFontOfSize:28];
}
- (void)setModel:(ZGLPhotoModel *)model {
    if (_model != model) {
        _model = model;
    }

    _imageHeigh = [_model.w integerValue] * [_model.h integerValue];
    [_waterImage setImageWithURL:[NSURL URLWithString:model.raw_url] placeholderImage:[UIImage imageNamed:@"nopic"]];
//    [_waterImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:model.raw_url]] placeholderImage:[UIImage imageNamed:@"nopic"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
//        
//    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
//        
//    }];
   
    
}
- (void)setCurrentCount:(NSInteger)currentCount {
    _currentCount = currentCount;
     self.leftLabel.text = [NSString stringWithFormat:@"%ld ", _currentCount];
    
}
- (void)setAllCount:(NSInteger)allCount {
    _allCount = allCount;
    _rightLabel.text = [NSString stringWithFormat:@"/ %ld", _allCount];
}

@end
